<?php
class DigCms_Plugin_ItemPlugin extends Zend_Controller_Plugin_Abstract {

    public function preDispatch(Zend_Controller_Request_Abstract $request) {
        DigCms_Service_Plugin::registerPlugins();
        if(! DigUi_Service_Template::isAdminTemplate()&&
                    ! DigUi_Service_Template::isAjaxTemplate()) {
            // you only modify the item on a public request
            $item = $request->getParam(DigCms_Library_Item_Controller::CURRENT_ITEM);
            if($item) {
                $plugins = DigCms_Service_Plugin::getPlugins($item->namespace);
                //Zend_Debug::dump($plugins);
                if($plugins) {
                    foreach ($plugins as $plugin) {
                        if(isset($plugin['modify'])) {
                            $item = call_user_func($plugin['modify'],$item);
                        }
                    }
                    $request->setParam(DigCms_Library_Item_Controller::CURRENT_ITEM, $item);
                }
            }

        }
    }
}
?>
